<style>
</style>
<template>
  <el-dialog
    title="删除银行卡"
    :visible.sync="innerVisible"
    width="400px"
    center
  >
    <el-row></el-row>
    <el-row>
      <el-col :span="16" :offset="4">
        <p>是否删除该张银行卡？</p>
        <p>删除后您可以再次绑定</p>
      </el-col>
    </el-row>
    <div slot="footer" >
      <el-row>
        <el-col :span="8" :offset="2">
          <el-button  type="info" class="btn btn-block" @click="hide">取消</el-button>
        </el-col>
        <el-col :span="8">
          <el-button  type="primary" class="btn  btn-block" style="margin-bottom: 10px;" :loading="loading"
                      @click="submit()">确认删除</el-button>
        </el-col>
        <div class="clearfix"></div>
      </el-row>
    </div>
    <div class="clearfix"></div>
  </el-dialog>
</template>
<script>
import {dotData} from '@/utils'
export default{
  components: {
  },
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    bankCardId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      loading: false,
      innerVisible: false
    }
  },
  created() {},
  watch: {
    // 监听并更新传进来的 visible
    visible(val, oldVal) {
      if (val === oldVal) {
        return
      }
      this.innerVisible = val
    },
    // 监听 并根据innerVisible的新值更新父组件visible的值
    innerVisible(val, oldVal) {
      if (val === oldVal) {
        return
      }
      this.$emit('update:visible', val)
    }
  },
  computed: {
    confirmImg() {
      return this.confirmArr.length
    }
  },
  methods: {
    hide() {
      this.innerVisible = false
    },
    // 确认删除
    submit() {
      this.loading = true
      console.log('即将提交的卡id', this.bankCardId)
      this.$ajax.post('/ms-user-wallet/wallet/wallet-banks-delete', {id: this.bankCardId}).then(response => {
        const success = dotData(response, 'success')
        this.innerVisible = false
        this.loading = false
        if (success) {
          this.$confirm('删除成功', '提示', {
            type: 'success',
            center: true,
            confirmButtonText: '确定',
            showCancelButton: false,
            closeOnclickModal: false
          }).then(_ => {
            // this.$router.push({path: '/ss-erp/myWallet/bankCardIndex'})
            this.$emit('refresh', true)
          })
        }
      })
    }
  }
}
</script>
